package com.brycen.bio.text;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * 客户端：文本传输
 */
public class client {
    public static void main(String[] args)  {
        Socket socket = null;
        try {
            socket = new Socket("127.0.0.1",9999);
            OutputStream outputStream = socket.getOutputStream();

            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
            while (true){
                Scanner scanner = new Scanner(System.in);
                System.out.print("请输入内容：");
                String s = scanner.nextLine();
                //因为服务端是读取的一行数据，如果不加换行符，服务端则会一直等待
                bufferedWriter.write(s+"\n");
                bufferedWriter.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //关闭连接
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
